package com.aidex.biz.controller;

import java.util.List;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.page.PageDomain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import com.aidex.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.aidex.biz.domain.BizAssessToDeptDetails;
import com.aidex.biz.service.BizAssessToDeptDetailsService;
import com.aidex.common.utils.SecurityUtils;

/**
 * 考核部门Controller
 * @author sean
 * @email 2074844820@qq.com
 * @date 2024-11-29
 */
@RestController
@RequestMapping("/biz/bizAssessToDeptDetails")
public class BizAssessToDeptDetailsController extends BaseController
{
    @Autowired
    private BizAssessToDeptDetailsService bizAssessToDeptDetailsService;

    /**
     * 查询考核部门列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizAssessToDeptDetails:list')")
    @GetMapping("/list")
    public R<PageInfo> list(BizAssessToDeptDetails bizAssessToDeptDetails, HttpServletRequest request, HttpServletResponse response)
    {

        bizAssessToDeptDetails.setPage(new PageDomain(request, response));
        bizAssessToDeptDetails.setDeptId(SecurityUtils.getDeptId());
        bizAssessToDeptDetails.setAssessDept(SecurityUtils.getDeptId());
        return R.data(bizAssessToDeptDetailsService.findPage(bizAssessToDeptDetails));
    }

    /**
     * 获取考核部门详细信息
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizAssessToDeptDetails:query')")
    @GetMapping(value = "/{id}")
    public R<BizAssessToDeptDetails> detail(@PathVariable("id") String id)
    {
        return R.data(bizAssessToDeptDetailsService.get(id));
    }

    /**
     * 新增考核部门
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizAssessToDeptDetails:add')")
    @Log(title = "考核部门", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  BizAssessToDeptDetails bizAssessToDeptDetails)
    {
        return R.status(bizAssessToDeptDetailsService.save(bizAssessToDeptDetails));
    }

    /**
     * 修改考核部门
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizAssessToDeptDetails:edit')")
    @Log(title = "考核部门", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated BizAssessToDeptDetails bizAssessToDeptDetails)
    {
        return R.status(bizAssessToDeptDetailsService.save(bizAssessToDeptDetails));
    }


    /**
     * 删除考核部门
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizAssessToDeptDetails:remove')")
    @Log(title = "考核部门", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids)
    {
        return R.status(bizAssessToDeptDetailsService.deleteBizAssessToDeptDetailsByIds(ids));
    }

    /**
     * 获取最大编号
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizAssessToDeptDetails:query')")
    @GetMapping("/findMaxSort")
    public R findMaxSort()
    {
        return R.data(bizAssessToDeptDetailsService.findMaxSort(new BizAssessToDeptDetails()));
    }

    /**
     * 导出考核部门列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizAssessToDeptDetails:export')")
    @Log(title = "考核部门", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(BizAssessToDeptDetails bizAssessToDeptDetails)
    {

            if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                    bizAssessToDeptDetails.setCompanyId(null);
            }else{
                         bizAssessToDeptDetails.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                     }
        List<BizAssessToDeptDetails> list = bizAssessToDeptDetailsService.findList(bizAssessToDeptDetails);
        ExcelUtil<BizAssessToDeptDetails> util = new ExcelUtil<BizAssessToDeptDetails>(BizAssessToDeptDetails.class);
        return util.exportExcel(list, "考核部门数据");
    }

}
